<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>document</title>
    <style>
        * {
            margin: 0;
            padding: 0;
        }

        ul,
        ol {
            list-style: none;
        }

        html,
        body {
            width: 100%;
            height: 100%;
        }

        ul {
            width: 100%;
            height: 100%;
        }

        ul>li {
            width: 100%;
            height: 100%;

        }

        ol {
            position: fixed;
            top: 100px;
            left: 50px;
        }

        ol>li {
            width: 50px;
            height: 50px;
            border: 1px solid #000000;
            text-align: center;
            line-height: 50px;
            margin-top: -1px;
        }
    </style>
</head>

<body>
    <ul>
        <li>1</li>
        <li>2</li>
        <li>3</li>
        <li>4</li>
        <li>5</li>
    </ul>
    <ol>
        <li>11</li>
        <li>22</li>
        <li>33</li>
        <li>44</li>
        <li>55</li>
    </ol>
</body>
<script>
    var ulLis = document.querySelectorAll('ul>li')
    var olLis = document.querySelectorAll('ol>li')
    var colors = ['red', 'orange', 'yellow', 'green', 'blue']
    var target = 0
    var leader = 0
    var timer = null
    ulLis.forEach((item, index) => {
        item.style.backgroundColor = colors[index]
        olLis[index].style.backgroundColor = colors[index]

        olLis[index].onclick = function () {
            clearInterval(timer)
            // console.log('123');
            target = ulLis[index].offsetTop
            // console.log(target);
            timer = setInterval(() => {
                leader = leader + (target - leader) / 10
                // 这种写法不对
                // ulLis[index].style.top = leader+'px'
                // scrollTo(参数1，参数2)
                // 参数1：x方向 滚动距离
                // 参数1：Y方向 滚动距离
                window.scrollTo(0,leader)
            },30)
        }


    })

</script>

</html>